package com.ruoyi.web.controller.cashier;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.MembershipDurationCard;
import com.ruoyi.system.service.MembershipDurationCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/card")
@Api(tags = "桌台时长卡管理")
public class MembershipDurationCardController extends BaseController {

    @Autowired
    private MembershipDurationCardService cardService;

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询时长卡信息")
    public AjaxResult getById(@PathVariable Long id) {
        return AjaxResult.success(cardService.getById(id));
    }

    @PostMapping("/list")
    @ApiOperation("分页查询所有时长卡记录")
    public TableDataInfo list(MembershipDurationCard card) {
        startPage();
        List<MembershipDurationCard> list = cardService.list(new QueryWrapper<>(card));
        return getDataTable(list);
    }

    @PostMapping
    @ApiOperation("新增时长卡记录")
    public AjaxResult add(@RequestBody MembershipDurationCard card) {
        cardService.save(card);
        return AjaxResult.success();
    }

    @PutMapping
    @ApiOperation("更新时长卡记录")
    public AjaxResult update(@RequestBody MembershipDurationCard card) {
        cardService.updateById(card);
        return AjaxResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除时长卡记录")
    public AjaxResult delete(@PathVariable Long id) {
        cardService.removeById(id);
        return AjaxResult.success();
    }
}
